﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ds.DataBase.Model;

namespace Ds.DataBase.Migrations.SeedData
{
    public class JiaoZhiGongCreator
    {
        public static List<JiaoZhiGongInfo> JiaoZhiGongsInfos { get; private set; }

        private readonly UserInfoClassContext _context;

        public JiaoZhiGongCreator()
        {

        }

        public JiaoZhiGongCreator(UserInfoClassContext context)
        {
            _context = context;
            JiaoZhiGongsInfos = new List<JiaoZhiGongInfo>
            {
                new JiaoZhiGongInfo(){ShouJiHao = "13313313313",UpDateTime = DateTime.Now,XingMing = "测试管理员",kszw =_context.KeShiZhiWuContext.First(s=>s.zhiwu.zwmc=="主管"),Users = new UserInfo(){password = "123456",username = "admin",zt = 1}}
            };
        }
        public void Create()
        {
            CreateJiaoZhiGongs();
        }

        private void CreateJiaoZhiGongs()
        {
            foreach (var language in JiaoZhiGongsInfos)
            {
                AddLanguageIfNotExists(language);
            }
        }
        private void AddLanguageIfNotExists(JiaoZhiGongInfo jiaoZhiGongInfo)
        {
            if (_context.JiaoZhiGongInfoContext.Any(l => l.XingMing == jiaoZhiGongInfo.XingMing))
            {
                return;
            }
            _context.JiaoZhiGongInfoContext.Add(jiaoZhiGongInfo);
            _context.SaveChanges();
        }

    }
}
